﻿using System;

namespace Website
{
    public static class UriExtensionMethods
    {
        public static string AppendExtension(this Uri arg, string extension)
        {
            if (arg == null) throw new ArgumentNullException("arg");

            int index = arg.OriginalString.IndexOf('?');
            if (index == -1) index = arg.OriginalString.IndexOf('#');

            Uri uri = null;

            if (index == -1)
            {
                uri = new Uri(arg.OriginalString + extension);
            }
            else
            {
                uri = new Uri(String.Concat(arg.OriginalString.Substring(0, index), extension, arg.OriginalString.Substring(index)));
            }

            return uri.OriginalString;
        }

        public static string ToString(this Uri arg, string oldValue, string newValue)
        {
            return (arg == null) ? null as string : arg.OriginalString.Replace(oldValue, newValue);
        }
    }
}